<?php
namespace app\common\validate;
use think\Validate;

class User extends Validate
{
    protected $rule = [
        'phone'         => [
            'require',
            'max'    => 11,
            'regex'  => '/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|16[6]|(17[0,3,5-8])|(18[0-9])|19[89])\d{8}$/',
        ],
        'password'      => 'require|min:6|max:20',
        'repassword'    => 'confirm:password',
        'salt'          => 'require|length:6',
        'login_failure' => 'between:0,5',
        'status'        => 'in:1,2',
        'device'        => 'in:1,2,3,4,5',
        'code'          => 'require',
        '__token__'     => 'require|token',
    ];

    protected $field = [
        'phone'         => '手机号码',
        'password'      => '密码',
        'salt'          => '密码盐值',
        'login_failure' => '登录失败次数',
        'status'        => '状态',
        'device'        => '设备',
        'login_time'    => '最后登录时间',
        'last_login_ip' => '最后登录IP',
        'create_time'   => '创建时间',
        'update_time'   => '修改时间',
        'code'          => '推荐码',
        'phone_code'    => '手机验证码',
    ];

    protected $message = [
        'phone.require'         => '手机号码不能为空',
        'phone.max'             => '手机号码不能超过20位数',
        'phone.regex'           => '手机号码格式不正确',
        'password.require'      => '密码不能为空',
        'password.min'          => '密码长度 6-20 位之间',
        'password.max'          => '密码长度 6-20 位之间',
        'salt.require'          => '盐值不能为空',
        'salt.length'           => '盐值长度不等于6个字符',
        'login_failure.between' => '登录失败次数超过5次',
        'status.in'             => '状态异常',
        'device.in'             => '设备异常',
        'code.require'          => '推荐码不能为空',
        'phone_code.require'    => '手机验证码不能为空',
    ];

    protected $scene = [
        'register' => ['phone', 'password', 'repassword', 'code'],
        'login'    => ['phone', 'password'],
    ];
}
